<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商家详情 - 外卖APP</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        :root {
            --primary-color: #2563eb;
            --secondary-color: #3b82f6;
            --accent-color: #f59e0b;
            --text-primary: #1f2937;
            --text-secondary: #4b5563;
            --background-light: #f8fafc;
        }

        body {
            margin: 0;
            padding: 0;
            background: var(--background-light);
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }

        .phone-container {
            width: 390px;
            height: 844px;
            margin: 20px auto;
            background: white;
            position: relative;
            overflow: hidden;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
            border-radius: 40px;
        }

        .content {
            height: 100%;
            overflow-y: auto;
            background: var(--background-light);
        }

        .content::-webkit-scrollbar {
            width: 0;
        }

        .header {
            height: 200px;
            background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.6)), url('https://images.unsplash.com/photo-1552566626-52f8b828add9?w=800&auto=format&fit=crop');
            background-size: cover;
            background-position: center;
            padding: 15px;
            position: relative;
        }

        .back-button {
            position: absolute;
            top: 15px;
            left: 15px;
            width: 36px;
            height: 36px;
            background: rgba(255,255,255,0.9);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--text-primary);
            text-decoration: none;
            backdrop-filter: blur(5px);
        }

        .restaurant-header {
            position: absolute;
            bottom: 20px;
            left: 20px;
            right: 20px;
            color: white;
        }

        .restaurant-name {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 8px;
        }

        .restaurant-info {
            display: flex;
            gap: 15px;
            font-size: 14px;
            opacity: 0.9;
        }

        .menu-container {
            display: flex;
            height: calc(100% - 200px - 50px);
        }

        .category-list {
            width: 80px;
            background: white;
            overflow-y: auto;
        }

        .category-item {
            padding: 15px 10px;
            text-align: center;
            font-size: 13px;
            color: var(--text-secondary);
            border-left: 3px solid transparent;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .category-item.active {
            color: var(--primary-color);
            background: var(--background-light);
            border-left-color: var(--primary-color);
            font-weight: 500;
        }

        .dish-list {
            flex: 1;
            overflow-y: auto;
            padding: 15px;
        }

        .dish-item {
            display: flex;
            padding: 15px;
            background: white;
            border-radius: 12px;
            margin-bottom: 15px;
            transition: transform 0.2s ease;
        }

        .dish-item:hover {
            transform: translateY(-2px);
        }

        .dish-img {
            width: 100px;
            height: 100px;
            border-radius: 8px;
            object-fit: cover;
            margin-right: 15px;
        }

        .dish-info {
            flex: 1;
            position: relative;
        }

        .dish-name {
            font-size: 16px;
            font-weight: 500;
            margin-bottom: 5px;
            color: var(--text-primary);
        }

        .dish-desc {
            font-size: 12px;
            color: var(--text-secondary);
            margin-bottom: 10px;
        }

        .dish-price {
            color: #ee0a24;
            font-size: 16px;
            font-weight: 500;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .dish-price small {
            font-size: 12px;
        }

        .quantity-control {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .quantity-btn {
            width: 24px;
            height: 24px;
            border-radius: 50%;
            border: none;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s ease;
        }

        .quantity-btn.minus {
            background: #f3f4f6;
            color: var(--text-secondary);
        }

        .quantity-btn.plus {
            background: var(--primary-color);
            color: white;
        }

        .quantity-btn:hover {
            transform: scale(1.1);
        }

        .quantity-btn:active {
            transform: scale(0.95);
        }

        .quantity {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
            min-width: 20px;
            text-align: center;
        }

        .cart-bar {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 50px;
            background: white;
            display: flex;
            align-items: center;
            padding: 0 15px;
            box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
        }

        .cart-header {
            display: flex;
            align-items: center;
            flex: 1;
        }

        .cart-icon {
            width: 45px;
            height: 45px;
            background: var(--primary-color);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 20px;
            margin-right: 10px;
            position: relative;
            transition: all 0.3s ease;
            text-decoration: none;
        }

        .cart-icon:hover {
            transform: scale(1.05);
        }

        .cart-count {
            position: absolute;
            top: -5px;
            right: -5px;
            background: #ee0a24;
            color: white;
            font-size: 12px;
            padding: 2px 6px;
            border-radius: 10px;
            font-weight: 500;
        }

        .cart-total {
            flex: 1;
            font-size: 16px;
            font-weight: 500;
            color: var(--text-primary);
        }

        .cart-items {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 100%;
            max-height: 0;
            overflow: hidden;
            transition: all 0.3s ease;
            background: white;
            border-radius: 12px 12px 0 0;
            box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
            padding: 0 15px;
        }

        .cart-items.show {
            max-height: 300px;
            overflow-y: auto;
            padding: 15px;
        }

        .cart-items::-webkit-scrollbar {
            width: 4px;
        }

        .cart-items::-webkit-scrollbar-thumb {
            background: #cbd5e1;
            border-radius: 4px;
        }

        .cart-item {
            display: flex;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid #f3f4f6;
        }

        .cart-item:last-child {
            border-bottom: none;
        }

        .cart-item-img {
            width: 40px;
            height: 40px;
            border-radius: 4px;
            object-fit: cover;
            margin-right: 10px;
        }

        .cart-item-info {
            flex: 1;
            min-width: 0;
            margin-right: 10px;
        }

        .cart-item-name {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
            margin-bottom: 2px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .cart-item-specs {
            font-size: 12px;
            color: var(--text-secondary);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .cart-item-price {
            font-size: 14px;
            color: #ee0a24;
            font-weight: 500;
            white-space: nowrap;
            margin-right: 15px;
        }

        .quantity-control {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .quantity-btn {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            border: none;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.2s ease;
            padding: 0;
        }

        .quantity-btn.minus {
            background: #f3f4f6;
            color: var(--text-secondary);
        }

        .quantity-btn.plus {
            background: var(--primary-color);
            color: white;
        }

        .quantity-btn:hover {
            transform: scale(1.1);
        }

        .quantity-btn:active {
            transform: scale(0.95);
        }

        .quantity-btn i {
            font-size: 12px;
        }

        .quantity {
            font-size: 14px;
            font-weight: 500;
            color: var(--text-primary);
            min-width: 20px;
            text-align: center;
        }

        .checkout-button {
            background: var(--primary-color);
            color: white;
            border: none;
            padding: 8px 20px;
            border-radius: 20px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            text-decoration: none;
            white-space: nowrap;
        }

        .checkout-button:hover {
            opacity: 0.9;
            transform: translateY(-1px);
        }

        .checkout-button:active {
            transform: scale(0.98);
        }

        .checkout-button.disabled {
            background: #e5e7eb;
            color: var(--text-secondary);
            cursor: not-allowed;
        }
    </style>
</head>
<body>
    <div class="phone-container">
        <div class="content">
            <div class="header">
                <a href="index.html" class="back-button">
                    <i class="bi bi-chevron-left"></i>
                </a>
                <div class="restaurant-header">
                    <div class="restaurant-name">川味小馆</div>
                    <div class="restaurant-info">
                        <span>评分 4.9</span>
                        <span>月售 3000+</span>
                        <span>25分钟</span>
                    </div>
                </div>
            </div>

            <div class="menu-container">
                <div class="category-list">
                    <div class="category-item active">热销</div>
                    <div class="category-item">川菜</div>
                    <div class="category-item">小炒</div>
                    <div class="category-item">凉菜</div>
                    <div class="category-item">主食</div>
                    <div class="category-item">饮品</div>
                </div>

                <div class="dish-list">
                    <div class="dish-item">
                        <img src="https://images.unsplash.com/photo-1555126634-323283e090fa?w=200&auto=format&fit=crop" alt="麻婆豆腐" class="dish-img">
                        <div class="dish-info">
                            <div class="dish-name">麻婆豆腐</div>
                            <div class="dish-desc">嫩滑豆腐，香辣可口</div>
                            <div class="dish-price">
                                <div><small>¥</small>28</div>
                                <div class="quantity-control">
                                    <button class="quantity-btn minus">
                                        <i class="bi bi-dash"></i>
                                    </button>
                                    <span class="quantity">2</span>
                                    <button class="quantity-btn plus">
                                        <i class="bi bi-plus"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="dish-item">
                        <img src="https://images.unsplash.com/photo-1585937421612-70a008356fbe?w=200&auto=format&fit=crop" alt="水煮鱼" class="dish-img">
                        <div class="dish-info">
                            <div class="dish-name">水煮鱼</div>
                            <div class="dish-desc">新鲜草鱼，麻辣鲜香</div>
                            <div class="dish-price">
                                <div><small>¥</small>58</div>
                                <div class="quantity-control">
                                    <button class="quantity-btn minus">
                                        <i class="bi bi-dash"></i>
                                    </button>
                                    <span class="quantity">1</span>
                                    <button class="quantity-btn plus">
                                        <i class="bi bi-plus"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="dish-item">
                        <img src="https://images.unsplash.com/photo-1623341214825-9f4f963727da?w=200&auto=format&fit=crop" alt="宫保鸡丁" class="dish-img">
                        <div class="dish-info">
                            <div class="dish-name">宫保鸡丁</div>
                            <div class="dish-desc">鸡肉鲜嫩，花生酥脆</div>
                            <div class="dish-price">
                                <div><small>¥</small>32</div>
                                <div class="quantity-control">
                                    <button class="quantity-btn minus">
                                        <i class="bi bi-dash"></i>
                                    </button>
                                    <span class="quantity">0</span>
                                    <button class="quantity-btn plus">
                                        <i class="bi bi-plus"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="cart-bar">
                <div class="cart-header">
                    <a href="#" class="cart-icon" id="cartToggle">
                        <i class="bi bi-cart"></i>
                        <span class="cart-count">3</span>
                    </a>
                    <div class="cart-total">
                        总计: <span style="color: #ee0a24">¥114</span>
                    </div>
                </div>
                
                <div class="cart-items" id="cartItems">
                    <div class="cart-item">
                        <img src="https://images.unsplash.com/photo-1555126634-323283e090fa?w=200&auto=format&fit=crop" alt="麻婆豆腐" class="cart-item-img">
                        <div class="cart-item-info">
                            <div class="cart-item-name">麻婆豆腐</div>
                            <div class="cart-item-specs">嫩滑豆腐，香辣可口</div>
                        </div>
                        <div class="cart-item-price">¥28 × 2</div>
                        <div class="quantity-control">
                            <button class="quantity-btn minus" data-id="dish-0">
                                <i class="bi bi-dash"></i>
                            </button>
                            <span class="quantity">2</span>
                            <button class="quantity-btn plus" data-id="dish-0">
                                <i class="bi bi-plus"></i>
                            </button>
                        </div>
                    </div>
                    <div class="cart-item">
                        <img src="https://images.unsplash.com/photo-1585937421612-70a008356fbe?w=200&auto=format&fit=crop" alt="水煮鱼" class="cart-item-img">
                        <div class="cart-item-info">
                            <div class="cart-item-name">水煮鱼</div>
                            <div class="cart-item-specs">新鲜草鱼，麻辣鲜香</div>
                        </div>
                        <div class="cart-item-price">¥58 × 1</div>
                        <div class="quantity-control">
                            <button class="quantity-btn minus" data-id="dish-1">
                                <i class="bi bi-dash"></i>
                            </button>
                            <span class="quantity">1</span>
                            <button class="quantity-btn plus" data-id="dish-1">
                                <i class="bi bi-plus"></i>
                            </button>
                        </div>
                    </div>
                </div>

                <a href="cart-detail.html" class="checkout-button">
                    去结算
                </a>
            </div>
        </div>
    </div>

    <script>
        // 购物车数据
        let cart = {
            items: {},
            total: 0,
            count: 0
        };

        // 更新购物车UI
        function updateCartUI() {
            const cartItemsContainer = document.getElementById('cartItems');
            const cartCount = document.querySelector('.cart-count');
            const cartTotal = document.querySelector('.cart-total');
            const checkoutButton = document.querySelector('.checkout-button');
            
            // 更新购物车数量
            cartCount.textContent = cart.count;
            
            // 更新总价
            cartTotal.innerHTML = `总计: <span style="color: #ee0a24">¥${cart.total}</span>`;
            checkoutButton.textContent = `去结算 ¥${cart.total}`;
            
            // 更新购物车列表
            cartItemsContainer.innerHTML = '';
            
            for (let id in cart.items) {
                const item = cart.items[id];
                if (item.quantity > 0) {
                    const cartItem = document.createElement('div');
                    cartItem.className = 'cart-item';
                    cartItem.innerHTML = `
                        <img src="${item.image}" alt="${item.name}" class="cart-item-img">
                        <div class="cart-item-info">
                            <div class="cart-item-name">${item.name}</div>
                            <div class="cart-item-specs">${item.specs || ''}</div>
                        </div>
                        <div class="cart-item-price">¥${item.price} × ${item.quantity}</div>
                        <div class="quantity-control">
                            <button class="quantity-btn minus" data-id="${id}">
                                <i class="bi bi-dash"></i>
                            </button>
                            <span class="quantity">${item.quantity}</span>
                            <button class="quantity-btn plus" data-id="${id}">
                                <i class="bi bi-plus"></i>
                            </button>
                        </div>
                    `;
                    cartItemsContainer.appendChild(cartItem);
                }
            }

            // 更新结算按钮状态
            if (cart.count === 0) {
                checkoutButton.classList.add('disabled');
            } else {
                checkoutButton.classList.remove('disabled');
            }
        }

        // 更新商品数量
        function updateItemQuantity(id, name, price, delta, image, specs) {
            if (!cart.items[id]) {
                cart.items[id] = {
                    name: name,
                    price: price,
                    quantity: 0,
                    image: image,
                    specs: specs
                };
            }

            const newQuantity = cart.items[id].quantity + delta;
            
            if (newQuantity >= 0) {
                cart.items[id].quantity = newQuantity;
                cart.count += delta;
                cart.total += delta * price;
                
                // 更新菜品列表中的数量
                const dishItem = document.querySelector(`[data-id="${id}"]`).closest('.dish-item');
                dishItem.querySelector('.quantity').textContent = newQuantity;
                
                updateCartUI();
            }
        }

        // 初始化购物车
        document.addEventListener('DOMContentLoaded', function() {
            // 为每个菜品添加唯一ID
            document.querySelectorAll('.dish-item').forEach((item, index) => {
                const name = item.querySelector('.dish-name').textContent;
                const price = parseInt(item.querySelector('.dish-price div').textContent.replace('¥', ''));
                const quantity = parseInt(item.querySelector('.quantity').textContent);
                const image = item.querySelector('.dish-img').src;
                const specs = item.querySelector('.dish-desc').textContent;
                const id = `dish-${index}`;
                
                // 添加data-id属性
                item.setAttribute('data-id', id);
                item.querySelectorAll('.quantity-btn').forEach(btn => {
                    btn.setAttribute('data-id', id);
                });

                // 如果初始数量大于0，添加到购物车
                if (quantity > 0) {
                    cart.items[id] = {
                        name: name,
                        price: price,
                        quantity: quantity,
                        image: image,
                        specs: specs
                    };
                    cart.count += quantity;
                    cart.total += quantity * price;
                }
            });

            // 更新购物车UI
            updateCartUI();
        });

        // 购物车切换显示
        document.getElementById('cartToggle').addEventListener('click', function(e) {
            e.preventDefault();
            document.getElementById('cartItems').classList.toggle('show');
        });

        // 为所有加减按钮添加点击事件
        document.querySelectorAll('.quantity-btn').forEach(button => {
            button.addEventListener('click', function() {
                const id = this.getAttribute('data-id');
                const dishItem = document.querySelector(`[data-id="${id}"]`);
                const name = dishItem.querySelector('.dish-name').textContent;
                const price = parseInt(dishItem.querySelector('.dish-price div').textContent.replace('¥', ''));
                const image = dishItem.querySelector('.dish-img').src;
                const specs = dishItem.querySelector('.dish-desc').textContent;
                const delta = this.classList.contains('plus') ? 1 : -1;
                
                updateItemQuantity(id, name, price, delta, image, specs);
            });
        });
    </script>
</body>
</html> 